package com.zcc.blog.controller;

import com.zcc.blog.dto.LoginDto;
import com.zcc.blog.service.AccountService;
import com.zcc.blog.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author zcc
 */
@Api(tags = "账户")
@RestController
public class AccountController {

    @Autowired
    AccountService accountService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public Result login(@Validated @RequestBody LoginDto loginDto, HttpServletResponse response){
        return accountService.login(loginDto, response);
    }

    /**
     * 需要认证权限才能退出登录
     * @return
     */
    @ApiOperation("注销")
    @RequiresAuthentication
    @GetMapping("/logout")
    public Result logout() {
        return accountService.logout();
    }

}
